import { getQueryString, errorMsg } from '../../utils/tool.js'
import { getVPhone, wxNuoChe } from '../../utils/networkRequest.js'

//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    qcode: '',
    auto_number: '',
    nuocheWord: '',
    name: '',
    address: '',
    avatar: '',
  },
  onLoad: function (options) {
    let self = this;

    if (options.qcode || options.auto_number || options.nuocheWord || options.name) {
      this.setData({
        qcode: options.qcode,
        auto_number: options.auto_number,
        nuocheWord: options.nuocheWord,
        name: options.name,
        avatar: options.avatar,
      })
    }


    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        app.globalData.qqmapsdk && app.globalData.qqmapsdk.reverseGeocoder({
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          },
          success: function (res) {
            self.setData({ address: res.result.address })
          },
          fail: function (res) {
            console.log(res);
          },
          complete: function (res) {
            console.log(res);
          }
        });
      }
    })



  },
  oncallphone: function () {




    getVPhone(this.data.qcode, this.data.address, (r) => {
      if (r.code == 0) {
        wx.makePhoneCall({
          phoneNumber: r.data.safeNumber
        })
      } else {
        errorMsg(r.message);
      }

    })

  },
  goApply: function () {
    wx.navigateTo({
      url: '../applycodebox/apply/apply',
    })
  },
  onWxNuoChe: function () {
    let { qcode, address } = this.data;
    wxNuoChe(qcode, address, (r) => {
      if (r.code == 0) {
        wx.showToast({
          icon: "none",
          title: '通知成功',
        })
      } else {
        wx.showToast({
          icon: "none",
          title: r.message,
        })
      }
    })
  }


})
